import { _decorator, Animation, AudioSource, Component, director, Node, Toggle } from 'cc';
import { SoundManager } from './SoundManager';
import { CardGenerator } from './CardGenerate';
const { ccclass, property } = _decorator;

@ccclass('SettingManager')
export class SettingManager extends Component {
    @property({type: Node, tooltip: "设置面板"})
    private settingPanel: Node | null = null;
    @property({type: Node, tooltip: "是否确认退出到菜单面板"})
    private ifSureToBack: Node | null = null;
    @property({type: Node, tooltip: "背景音乐开关"})
    private ToggleBGM: Node | null = null;
    @property({type: Node, tooltip: "游戏音效开关"})
    private ToggleSFX: Node | null = null;
    start() {

    }

    update(deltaTime: number) {
        
    }

    protected onEnable(): void {
        this.ToggleBGM.getComponent(Toggle).isChecked = !SoundManager.getInstance().getBGMMuteStatus();
        this.ToggleSFX.getComponent(Toggle).isChecked = !SoundManager.getInstance().getSFXMuteStatus();
    }

    //点击返回按钮
    onClickBackBtn() {
        this.ifSureToBack.active = true;
        this.ifSureToBack.getComponent(Animation).play();
    }
    //点击确定按钮
    onClickSureBtn() {
        this.ifSureToBack.active = false;
        this.settingPanel.active = false;
        director.loadScene("MenuScene")
    }
    //点击取消按钮
    onClickCancelBtn() {
        this.ifSureToBack.active = false;
    }
    //关闭设置界面
    closeSettingPanel() {
        this.settingPanel.active = false;
    }

    //点击背景音乐开关
    onClickToggleBGM(event: Event) {
        SoundManager.getInstance().toggleBGMMute();
    }
    //点击音效开关
    onClickToggleSFX(event: Event) {
        SoundManager.getInstance().toggleSFXMute();
    }
}


